<h1>Usuarios</h1>
<%= form_tag users_path, :method => 'get', :id => "users_search" do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>
  </p>
<% end %>
<%= hidden_field_tag :direction, params[:direction] %>
<%= hidden_field_tag :sort, params[:sort] %>
<table id="users">
	<tr>
	  <th><%= sortable "name","Nombre" %></th>
	  <th><%= sortable "last_name","Apellido" %></th>
	  <th><%= sortable "rut" %></th>
	  <th><%= sortable "email" %></th>
	  <th></th>
	<th></th>
	<th></th>
	  <th><%= sortable "confirmation","Confirmados" %></th>
	<th><%= sortable "locked","Bloqueados" %></th>


	</tr>
<%altcount=0%>
<% @users.each do |user| %>
 <%if altcount==0%> 
	<%altcount=1%>
 	<tr>
 <%else%>
	<%altcount=0%>
	<tr class="alt">
 <%end%>
	<% if can? :manage, user %>
    <td><%= user.name %></td>
    <td><%= user.last_name %></td>
    <td><%= user.rut %></td>
	<td><%= user.email %></td>

    <td><%= link_to image_tag("/assets/iconos/ID.png", :size =>"20x20"), user %></td>
   	<td><%= link_to image_tag("/assets/iconos/Pencil.png", :size =>"20x20"), edit_user_path(user) %></td>
	<%= form_for(user) do |f| %>
	  <%= f.hidden_field :deleted,:value => user.id%>
	  <td><%= f.submit "Eliminar",:type => :image, :src => "assets/iconos/Trash.png",:class=>"eliminar" %></td>
	<% end %>
	<%if !user.confirmation%>
		<%= form_for(user) do |f| %>
		  <%= f.hidden_field :confirmation,:value => true%>
		  <td><%= f.submit "Confirmar" %></td>
		<% end %>
	<%else %>	
	<td>Si</td>
	<%end%>
	<%if user.locked or user.faild_attempts>3%>
		<%= form_for(user) do |f| %>
		  <%= f.hidden_field :locked,:value => false%>
		<%= f.hidden_field :faild_attempts,:value => 0%>
		  <td><%= f.submit "Desbloquear" %></td>
		<% end %>
	<%else %>	
		<td>No</td>
	<%end%>
	
  	<% end %>
  </tr>
<% end %>
</table>
<%= will_paginate @products %>
